~ chicken-core (chicken-5) /manual/Module (chicken string)
Trap1[[tags: manual]]
2[[toc:]]
3
4== Module (chicken string)
5
6This module contains procedures which can perform various useful
7string operations.
8
9=== conc
10
11<procedure>(conc X ...)</procedure>
12
13Returns a string with the string-represenation of all arguments
14concatenated together. {{conc}} could be implemented as
15
16<enscript highlight=scheme>
17(define (conc . args)
18 (apply string-append (map ->string args)) )
19</enscript>
20
21
22
23=== ->string
24
25<procedure>(->string X)</procedure>
26
27Returns a string-representation of {{X}}.
28
29
30=== string-chop
31
32<procedure>(string-chop STRING LENGTH)</procedure>
33
34Returns a list of substrings taken by ''chopping'' {{STRING}} every {{LENGTH}}
35characters:
36
37<enscript highlight=scheme>
38(string-chop "one two three" 4) ==> ("one " "two " "thre" "e")
39</enscript>
40
41
42=== string-chomp
43
44<procedure>(string-chomp STRING [SUFFIX])</procedure>
45
46If {{STRING}} ends with {{SUFFIX}}, then this procedure returns a copy
47of its first argument with the suffix removed, otherwise returns
48{{STRING}} unchanged. {{SUFFIX}} defaults to {{"\n"}}.
49
50
51=== string-compare3
52
53<procedure>(string-compare3 STRING1 STRING2)</procedure><br>
54<procedure>(string-compare3-ci STRING1 STRING2)</procedure>
55
56Perform a three-way comparison between the {{STRING1}} and {{STRING2}},
57returning either {{-1}} if {{STRING1}} is lexicographically less
58than {{STRING2}}, {{0}} if it is equal, or {{1}} if it s greater.
59{{string-compare3-ci}} performs a case-insensitive comparison.
60
61
62=== string-intersperse
63
64<procedure>(string-intersperse LIST [STRING])</procedure>
65
66Returns a string that contains all strings in {{LIST}} concatenated
67together. {{STRING}} is placed between each concatenated string and
68defaults to {{" "}}.
69
70<enscript highlight=scheme>
71(string-intersperse '("one" "two") "three")
72</enscript>
73
74is equivalent to
75
76<enscript highlight=scheme>
77(apply string-append (intersperse '("one" "two") "three"))
78</enscript>
79
80
81=== string-split
82
83<procedure>(string-split STRING [DELIMITER-STRING [KEEPEMPTY]])</procedure>
84
85Split string into substrings delimited by any of the characters given
86in the delimiter string. If no delimiters are specified, a string
87comprising the tab, newline and space characters is assumed. If the
88parameter {{KEEPEMPTY}} is given and not {{#f}}, then empty substrings
89are retained:
90
91<enscript highlight=scheme>
92(string-split "one two three") ==> ("one" "two" "three")
93(string-split "foo:bar::baz:" ":" #t) ==> ("foo" "bar" "" "baz" "")
94(string-split "foo:bar:baz,quux,zot" ":," ) ==> ("foo" "bar" "baz" "quux" "zot")
95</enscript>
96
97
98=== string-translate
99
100<procedure>(string-translate STRING FROM [TO])</procedure>
101
102Returns a fresh copy of {{STRING}} with characters matching
103{{FROM}} translated to {{TO}}. If {{TO}} is omitted, then
104matching characters are removed. {{FROM}} and {{TO}} may be
105a character, a string or a list. If both {{FROM}} and {{TO}}
106are strings, then the character at the same position in {{TO}}
107as the matching character in {{FROM}} is substituted.
108
109
110=== string-translate*
111
112<procedure>(string-translate* STRING SMAP)</procedure>
113
114Substitutes elements of {{STRING}} according to {{SMAP}}.
115{{SMAP}} should be an association-list where each element of the list
116is a pair of the form {{(MATCH . REPLACEMENT)}}. Every occurrence of
117the string {{MATCH}} in {{STRING}} will be replaced by the string
118{{REPLACEMENT}}:
119
120<enscript highlight=scheme>
121(string-translate*
122 "<h1>this is a \"string\"</h1>"
123 '(("<" . "<") (">" . ">") ("\"" . """)) )
124=> "<h1>this is a "string"</h1>"
125</enscript>
126
127
128=== substring=?
129
130<procedure>(substring=? STRING1 STRING2 [START1 [START2 [LENGTH]]])</procedure><br>
131<procedure>(substring-ci=? STRING1 STRING2 [START1 [START2 [LENGTH]]])</procedure>
132
133Returns {{#t}} if the strings {{STRING1}} and {{STRING2}} are equal,
134or {{#f}} otherwise. The comparison starts at the positions
135{{START1}} and {{START2}} (which default to 0), comparing {{LENGTH}}
136characters (which defaults to the minimum of the remaining length of
137both strings).
138
139
140=== substring-index
141
142<procedure>(substring-index MAYBE-SUBSTRING STRING [START])</procedure><br>
143<procedure>(substring-index-ci MAYBE-SUBSTRING STRING [START])</procedure>
144
145Searches for first index in string {{STRING}} where string
146{{MAYBE-SUBSTRING}} occurs. If the optional argument {{START}} is given,
147then the search starts at that index. {{substring-index-ci}}
148is a case-insensitive version of {{substring-index}}.
149
150
151=== reverse-list->string
152
153<procedure>(reverse-list->string LIST)</procedure>
154
155Returns a string with the characters in {{LIST}} in reverse
156order. This is equivalent to {{(list->string (reverse LIST))}}, but
157much more efficient.
158
159
160=== reverse-string-append
161
162<procedure>(reverse-string-append LIST)</procedure>
163
164{{(apply string-append (reverse LIST))}}
165
166
167---
168Previous: [[Module (chicken sort)]]
169
170Next: [[Module (chicken syntax)]]